<?php
/**
 * Created by litong on Date: 2019/2/24 0024 下午 10:25
 */
$host="localhost";$username="root";$password="";$dbname="php_study";
$connection = new mysqli($host, $username, $password, $dbname);
if($connection->connect_error){
  echo $connection->connect_error;
}
$sql="INSERT INTO my_guests (firstname, lastname, email) VALUES (?, ?, ?)";
//预处理及绑定
$statement = $connection->prepare($sql);
$statement->bind_param("sss",$firstname,$lastname,$email);
// 设置参数并执行
$firstname = "John";$lastname = "Doe";$email = "john@example.com";$statement->execute();
$firstname = "Mary";$lastname = "Moe";$email = "mary@example.com";$statement->execute();
$firstname = "Julie";$lastname = "Dooley";$email = "julie@example.com";$statement->execute();
echo "新记录插入成功";
$statement->close();$connection->close();
?>
